<template>
  <Container>
    <div class="container-header title title-center" slot="header">礼包详情
      <Button size="large" class="fl btn-back"  icon="ios-arrow-back" @click="jumpPage">返回</Button>
    </div>
    <div class="bg-light pb mb">
      <div class="container-title">礼包设置</div>
      <Form :label-width="90" ref="form" :model="form">
        <FormItem label="礼包名称:">
          <span class="wp80">{{form.packageName}}</span>
        </FormItem>
        <FormItem label="发放渠道:">
          <span>{{form.couponSendChannelEnum | SendChannelFilter}}</span>
        </FormItem>
        <FormItem label="礼包说明：">
          <p class="wp80">{{form.remark}}</p>
        </FormItem>
      </Form>
    </div>
    <homeTable
      :translate="186"
      :list="list"
      @getData="getData"
      @onPageSizeChange="onPageSizeChange"
      @onPageChange="onPageChange"
      />
  </Container>
</template>
<script>
import GiftBagInfoData from './info/GiftBagInfoData'
import homeTable from '~/homeTable'
export default {
  components: {
    homeTable
  },
  data () {
    return {
      id: this.$route.query.id || null,
      list: GiftBagInfoData,
      form: {
        packageName: '',
        couponSendChannelEnum: 2,
        remark: ''
      }
    }
  },
  mounted() {
    this.getData()
  },
  methods: {
    jumpPage() {
      this.$router.back()
    },
    getData() {
      this.list.status = "loading"
      this.$ajaxGet(`/coupon/coupon_package/detail/${this.id}`).then(data => {
        this.id = data.id
        this.form.packageName = data.packageName
        this.form.couponSendChannelEnum = data.couponSendChannelEnum
        this.form.remark = data.remark
        this.getCouponPackData()
      }).catch(() => {
        this.list.status = 'error'
      })
    },
    getCouponPackData() { // 所含券table
      let param = {
        current: this.list.currentPage,
        size: this.list.pageSize,
        couponPackageId: this.id
      }
      this.list.status = "loading"
      this.$jsonPost("/coupon/coupon_package/item_page", param).then(data => {
        this.loading = false
        this.list.data = []
        this.list.totalItem = Number(data.total)
        this.list.data = (data.records || [])
        this.list.status = "pass"
      }).catch(() => {  
        this.list.status = "error"
      })
    },
    onPageChange(number) {
			this.list.currentPage = number;
      this.getCouponPackData();
		},
    onPageSizeChange(pageSize) {
			this.list.currentPage = 1;
			this.list.pageSize = pageSize;
			this.getCouponPackData();
		}
  },
  filters: {
    SendChannelFilter(v) {
      let list = {
        'NONE_LIMIT': '不限',
        'TIRE_INSURANCE': '轮胎保小程序',
        'CLOUD_APP': '中策云店',
        'SALESMAN': '业务通'
      }
      return list[v]
    }
  }
}
</script>